package netty.coffee;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 解析Coffee
 *
 * @author Administrator
 */
class CoffeeEncoder extends MessageToByteEncoder<Object> {
    private static final Logger LOG = LoggerFactory.getLogger(CoffeeEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) {
        byteBuf.writeBytes(this.encode(o));
    }


    public <T> ByteBuf encode(T obj) {
        ByteBuf byteBuf = Unpooled.buffer();
        String response = (String) obj;
        byteBuf.writeByte(0x02);
        byteBuf.writeBytes(response.getBytes());
        byteBuf.writeByte(0x17);
        return byteBuf;
    }

}
